package com.example.shoppingmallspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.shoppingmallspringboot.entity.Goods;
import com.example.shoppingmallspringboot.mapper.GoodsMapper;
import com.example.shoppingmallspringboot.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> getAllGoods() {
        return goodsMapper.selectList(null);
    }

    @Override
    public List<Goods> getGoods(Integer categoryId) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("category_id", categoryId);
        return goodsMapper.selectList(wrapper);
    }

    @Override
    public List<Goods> searchGoods(String searchText) {
        return goodsMapper.searchGoodsList(searchText);
    }

    @Override
    public List<Goods> getGoodsById(Integer goodsId) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id", goodsId);
        return goodsMapper.selectList(wrapper);
    }
} 